//
//  MainViewController.m
//  GestureLock
//
//  Created by YR on 2017/6/5.
//  Copyright © 2017年 YR. All rights reserved.
//

#import "MainViewController.h"

#import "Masonry.h"
#import "YWGesturesViewController.h"

@interface MainViewController ()

@property (nonatomic) UIButton *createLock; //创建手势
@property (nonatomic) UIButton *validateLock;   //  验证手势
@property (nonatomic) UIButton *deleteLock;   //  删除手势

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor grayColor];
    
    [self.view addSubview:self.createLock];
    [self.view addSubview:self.validateLock];
    [self.view addSubview:self.deleteLock];
    
    [_createLock mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).mas_offset(100);
        make.width.mas_equalTo(self.view.frame.size.width-100);
        make.centerX.equalTo(self.view);
    }];
    [_validateLock mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(_createLock.mas_bottom).with.offset(50);
        make.width.equalTo(_createLock);
    }];
    [_deleteLock mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(_validateLock.mas_bottom).with.offset(50);
        make.width.equalTo(_validateLock);
    }];
}

- (void)createLockAction:(UIButton *)sender {
    YWGesturesViewController *vc = [[YWGesturesViewController alloc] initWithLockType:kYWGesturesUnLockTypeCreate];
    [self presentViewController:vc animated:YES completion:nil];
}

- (void)validateLockAction:(UIButton *)sender {
    if ([YWGesturesViewController gesturesPassword].length <= 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"还没有设置手势密码" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
        [alertView show];
        return;
    }
    
    YWGesturesViewController *vc = [[YWGesturesViewController alloc] initWithLockType:kYWGesturesUnLockTypeValid];
    [self presentViewController:vc animated:YES completion:nil];
}

- (void)deleteLockAction:(UIButton *)sender {
    [YWGesturesViewController deleteGesturesPassword];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

- (UIButton *)createLock {
    if (!_createLock) {
        _createLock = [[UIButton alloc] init];
        [_createLock setTitle:@"创建手势" forState:UIControlStateNormal];
        [_createLock setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _createLock.titleLabel.font = [UIFont systemFontOfSize:15];
        [_createLock addTarget:self action:@selector(createLockAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _createLock;
}

- (UIButton *)validateLock {
    if (!_validateLock) {
        _validateLock = [[UIButton alloc] init];
        [_validateLock setTitle:@"验证手势" forState:UIControlStateNormal];
        [_validateLock setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _validateLock.titleLabel.font = [UIFont systemFontOfSize:15];
        [_validateLock addTarget:self action:@selector(validateLockAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _validateLock;
}

- (UIButton *)deleteLock {
    if (!_deleteLock) {
        _deleteLock = [[UIButton alloc] init];
        [_deleteLock setTitle:@"删除手势" forState:UIControlStateNormal];
        [_deleteLock setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _deleteLock.titleLabel.font = [UIFont systemFontOfSize:15];
        [_deleteLock addTarget:self action:@selector(deleteLockAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteLock;
}

@end
